<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/26
 * Time: 15:03
 */

namespace app\modules\fieldwork\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use app\modules\fieldwork\models\FieldworkEnpty;
use app\modules\admin\models\PublicMethod;
use app\modules\admin\models\AesManageForm;



class FieldworkController extends Controller
{
    public $enableCsrfValidation = false;

    //public $layout='publicweb';
    public function actionIndex()
    {
        $this->layout = false;


//        $ch=copy( Yii::getAlias('@tem_uploads').'/20160511155108482795.jpg',   Yii::getAlias('@uploads').'/888/20160511155108482795.jpg');
//        exit;
        //   var_dump(hash('sha256', '123456', true)) ;
        //   var_dump(md5('1'));

        //    $AesManageForm= new AesManageForm(md5('2idg31u4uhkj6n1b40qqqdipc41605270839016879'));
        //     echo chr(15) . "<br>"; // 十进制
//     var_dump('加密----------------');


//     var_dump($AesManageForm->encrypt('{"store_id":"1","order_type":"1","order_state":"1","sort_column":"1","sort_order":"asc","page_now":"1","page_size":"5"}'));
        //  var_dump('解密----------------');
//     var_dump($AesManageForm->decrypt('VBVlqntvi7DghqilKZwTjANuIraSJP-uLBI4eeoEzCBwoabFHug6AVURMzFp5f2mUBFuPHMyD53t7ptlLKn9EZn5uVzMHibWNkbgzK--1OjkabZTpo7PHiDaP5XBdpjSPXbqLu3Cl6Dq3qxl_zPi7R3fzbgEy_NO6b4gH6VZ62Q')) ;
        //   exit;

        try {
            return $this->render('index');
        } catch (\Exception $ex) {
            echo json_encode($ex->getMessage());
            exit;
        }
    }

    //获取种子
    public  function  actionGettokenseed(){

        $result=array();
        $this->layout = false;

        $lifeTime =  1800;
        date_default_timezone_set('UTC');

        try{

            session_start();
            setcookie("PHPSESSID", session_id(), time() + $lifeTime, "/");

        }catch (\Exception $ex) {

            $result['err_code'] = 40010;
            $result['err_msg'] = $ex->getMessage(); //  获取种子失败
            return json_encode($result);
        }


        try{

            $TokenSeed=date('ymdHis',time()).rand(1000,9999);  //12位时间 +4位随机数
            $_SESSION['TokenSeed']=$TokenSeed;
            setcookie("TokenSeed", $TokenSeed, time() + $lifeTime, "/");

        }catch (\Exception $ex) {

            $result['err_code'] = 40010;
            $result['err_msg'] = $ex->getMessage(); //  获取种子失败
            return json_encode($result);
        }

        $result['TokenSeed']=$TokenSeed;

        $result['SessionId']=session_id();
//        $result['$_SESSION']=$_SESSION;
        return json_encode($result);

    }

    //外勤系统管理员登录
    public function actionManagelogin()
    {

        // error_log("Oracle数据库不可用!", 0);exit;
        //  phpinfo();exit;
        //  throw new \Exception("Value must be 1 or below");exit;
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }


        //判断参数是否合法
        if( array_key_exists("m_account", $decode)
            &&  array_key_exists("m_password",$decode)
            && !empty($decode['m_account'])
            && !empty($decode['m_password'])
        ){


        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };


        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_ManageLogin',
            'Procedure_data_in'=>array(
                'm_account'=>$decode['m_account'],
                'm_password'=>md5($decode['m_password']),
            ),
            'Procedure_data_out'=>array(
                'result_state'=>'result_state'
            )
        );

        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['result_state']==1){

                if(sizeof($data)>1){
                    $result=  $data[1];
                }else{

                    $result['err_code'] = 50004;
                    $result['err_msg'] = '管理员信息不存在';
                    return json_encode($result);
                }


                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                    //   $result=json_decode($crypttext);


                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败
                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['result_state']) {
                    case 0:
                        $result['err_code'] = 50001;
                        $result['err_msg'] = '账号或密码错误';
                        break;
                    case 2:
                        $result['err_code'] = 50002;
                        $result['err_msg'] = '账号没有权限登录外勤系统';
                        break;
                    default:
                        $result['err_code'] = 50001;
                        $result['err_msg'] = '账号或密码错误';   //0
                        break;
                }

                return json_encode($result);
            }
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }

    }


    //外勤工单列表
    public  function actionWorkorderlist(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }
        //判断参数是否合法
        if( array_key_exists("store_id", $decode)
            &&  array_key_exists("order_type",$decode)
            &&  array_key_exists("order_state",$decode)
            &&  array_key_exists("sort_column",$decode)
            &&  array_key_exists("sort_order",$decode)
            &&  array_key_exists("page_now",$decode)
            &&  array_key_exists("page_size",$decode)
        ){


        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };


        //工单状态 -1 不限   0未开始处理  1处理中 2处理完成 3作废
        if ($decode['order_state']==-1){
            $decode['order_state']='';

        }else{
            $decode['order_state']=' and a.deal_state='.$decode['order_state'];
        }

        //工单类型  ：1 车主送车 2 租客取车 3 租客还车 4 车主取车   0不限    5 停车    6取车
        if($decode['order_type']==0){
            $decode['order_type']=' and a.workorder_type <5 ';
        }else{
            $decode['order_type']=' and a.workorder_type='.$decode['order_type'];
        }

        // 工单开始时间   工单结束时间

        if ($decode['start_time']==''&& $decode['end_time']==''){  //默认是当天的订单

            $decode['start_time']=' and date(a.workorder_start)=date(now())';
            $decode['end_time']=' ';

        }else{ //历史工单

            if($decode['start_time']!=null && $decode['start_time']!=''){
                $decode['start_time']=' and a.workorder_start>"'.$decode['start_time'].'"';
            }else{
                $decode['start_time']=' ';
            }
            if($decode['end_time']!=null && $decode['end_time']!=''){
                $decode['end_time']=' and a.workorder_start<"'. $decode['end_time'].'"';
            }else{
                $decode['end_time']=' ';
            }

        }
        if($decode['sort_column']==1){  //'work_startime'
            $decode['sort_column']=' order by a.workorder_start  ';
        }else{  //默认按照创建时间排序  create_time
            $decode['sort_column']= ' order by a.create_time  ';
        }
        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_WorkOrderList',
            'Procedure_data_in'=>array(
                '_stores_id'=>$decode['store_id'], //门店编号
                '_orders_type'=>$decode['order_type'],//工单类型 0，1，2，3，4
                '_orders_state'=>$decode['order_state'],//  工单状态 -1 不限   0未开始处理  1处理中 2处理完成 3作废     工单状态 当前订单 历史订单  1 当天待处理工单 历史已处理工单
                '_start_time'=>$decode['start_time'], // 开始时间
                '_end_time'=>$decode['end_time'], //结束时间
                '_sort_column'=>$decode['sort_column'], //排序条件 剩余时间
                '_sort_order'=>$decode['sort_order'] ,//排序顺序 desc asc
                '_page_now'=>$decode['page_now'],//当前页数
                '_page_size'=>$decode['page_size'],  //每页条数

            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        // var_dump($data);
        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state']==1){

                if(sizeof($data)>2){

                    foreach ($data[1] as  $k=> $val){
                        $result[$k]=$val;

                        if($val['tem_result']==1 && $val['tem_result2']==1){
                            $result[$k]['identity_state']=1;  // 用户身份认证已成功，不需要重复认证
                        }elseif($val['tem_result']==0 || $val['tem_result2']==0){
                            $result[$k]['identity_state']=2;  // 正在审核处理中
                        }elseif($val['tem_result']==2 || $val['tem_result2']==2){
                            $result[$k]['identity_state']=3;  //该用户身份认证信息 审核处理失败
                        }else{
                            $result[$k]['identity_state']=0; //未提交认证 未认证
                        }
                        unset($result[$k]['tem_result']);
                        unset($result[$k]['tem_result2']);

                        $result[$k]['car_identity'] = $val['car_identity']>=0?$val['car_identity']:-1;

                        foreach($data[2] as $key=>$value){


                            if($val['workorder_id']==$value['workorder_id']){

                                $result[$k]['step_data'][$key]['workstep_id']=$value['workstep_id'];
                                $result[$k]['step_data'][$key]['workstep_name']=$value['workstep_name'];
                                $result[$k]['step_data'][$key]['deal_state']=$value['deal_state'];
                                $result[$k]['step_data'][$key]['waitdeal_time']=$value['waitdeal_time'];
                                $result[$k]['step_data'][$key]['deal_time']=$value['deal_time'];
                                $result[$k]['step_data'][$key]['manage_fullname']=$value['manage_fullname'];
                                //  $result[$k]['step_data'][$key]['stepresult_id']=$value['stepresult_id'];
                            }
                        }
                        if(array_key_exists("step_data",$result[$k]) ){
                            $result[$k]['step_data']= array_values($result[$k]['step_data']);
                        }

                    }
                }else{
                    $result['err_code'] = 50005;
                    $result['err_msg'] = '当前时间段内没有工单';
                    return json_encode($result);
                }

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败
                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {

                $result['err_code'] = 50003;
                $result['err_msg'] = '服务器错误';   //0

                return json_encode($result);
            }
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }


    }

    //泊车外勤工单
    public  function actionCarstoplist(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if( array_key_exists("store_id", $decode)
            &&  array_key_exists("order_type",$decode)
            &&  array_key_exists("order_state",$decode)
            &&  array_key_exists("sort_column",$decode)
            &&  array_key_exists("sort_order",$decode)
            &&  array_key_exists("page_now",$decode)
            &&  array_key_exists("page_size",$decode)
        ){


        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };


        //工单状态 -1 不限   0未开始处理  1处理中 2处理完成 3作废
        if ($decode['order_state']==-1){
            $decode['order_state']='';

        }else{
            $decode['order_state']=' and a.deal_state='.$decode['order_state'];
        }

        //工单类型  ：1 车主送车 2 租客取车 3 租客还车 4 车主取车   0不限（5,6）    5 停车    6取车
        if($decode['order_type']==0){
            $decode['order_type']=' and a.workorder_type >4 ';
        }else{
            $decode['order_type']=' and a.workorder_type='.$decode['order_type'];
        }

        // 工单开始时间   工单结束时间

        if ($decode['start_time']==''&& $decode['end_time']==''){  //默认是当天的订单

            $decode['start_time']=' and date(a.workorder_start)=date(now())';
            $decode['end_time']=' ';

        }else{ //历史工单

            if($decode['start_time']!=null && $decode['start_time']!=''){
                $decode['start_time']=" and a.workorder_start>'".$decode['start_time']."'";
            }else{
                $decode['start_time']=' ';
            }
            if($decode['end_time']!=null && $decode['end_time']!=''){
                $decode['end_time']=" and a.workorder_start<'". $decode['end_time']."'";
            }else{
                $decode['end_time']=' ';
            }

        }

        if($decode['sort_column']==1){  //'work_startime'
            $decode['sort_column']=' order by a.workorder_start  ';
        }else{  //默认按照创建时间排序  create_time
            $decode['sort_column']= ' order by a.create_time  ';
        }
        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_WorkOrderCarStopList',
            'Procedure_data_in'=>array(
                '_stores_id'=>$decode['store_id'], //门店编号
                '_orders_type'=>$decode['order_type'],//工单类型 0，1，2，3，4
                '_orders_state'=>$decode['order_state'],//  工单状态 -1 不限   0未开始处理  1处理中 2处理完成 3作废     工单状态 当前订单 历史订单  1 当天待处理工单 历史已处理工单
                '_start_time'=>$decode['start_time'], // 开始时间
                '_end_time'=>$decode['end_time'], //结束时间
                '_sort_column'=>$decode['sort_column'], //排序条件 剩余时间
                '_sort_order'=>$decode['sort_order'] ,//排序顺序 desc asc
                '_page_now'=>$decode['page_now'],//当前页数
                '_page_size'=>$decode['page_size'],  //每页条数

            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );

        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state']==1){

                if(sizeof($data)>2){

                    foreach ($data[1] as  $k=> $val){

                        $result[$k]=$val;
                        if($val['tem_result']==1 && $val['tem_result2']==1){
                            $result[$k]['identity_state']=1;  // 用户身份认证已成功，不需要重复认证
                        }elseif($val['tem_result']===0 || $val['tem_result2']===0){
                            $result[$k]['identity_state']=2;  // 正在审核处理中
                        }elseif($val['tem_result']==2 || $val['tem_result2']==2){
                            $result[$k]['identity_state']=3;  //该用户身份认证信息 审核处理失败
                        }else{
                            $result[$k]['identity_state']=0; //未提交认证 未认证
                        }
                        unset($result[$k]['tem_result']);
                        unset($result[$k]['tem_result2']);


                        foreach($data[2] as $key=>$value){


                            if($val['workorder_id']==$value['workorder_id']){

                                $result[$k]['step_data'][$key]['workstep_id']=$value['workstep_id'];
                                $result[$k]['step_data'][$key]['workstep_name']=$value['workstep_name'];
                                $result[$k]['step_data'][$key]['deal_state']=$value['deal_state'];
                                $result[$k]['step_data'][$key]['waitdeal_time']=$value['waitdeal_time'];
                                $result[$k]['step_data'][$key]['deal_time']=$value['deal_time'];
                                $result[$k]['step_data'][$key]['manage_fullname']=$value['manage_fullname'];
                                //  $result[$k]['step_data'][$key]['stepresult_id']=$value['stepresult_id'];
                            }
                        }
                        if(array_key_exists("step_data",$result[$k]) ){
                            $result[$k]['step_data']= array_values($result[$k]['step_data']);
                        }
                    }


                }else{
                    $result['err_code'] = 50005;
                    $result['err_msg'] = '当前时间段内没有工单';
                    return json_encode($result);
                }

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败
                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {

                $result['err_code'] = 50003;
                $result['err_msg'] = '服务器错误';   //0

                return json_encode($result);
            }
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }


    }


    //客户信息查询
    public  function  actionWorkselectuser(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if( array_key_exists("user_date", $decode) )
        {
            if(preg_match('/^1([0-9]{9})/',$decode['user_date'])){

                $decode['type']=1;
            }else{
                $decode['type']=2;
            }

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_SelectUser',
            'Procedure_data_in'=>array(
                '_type'=>$decode['type'],
                '_user_date'=>$decode['user_date'], //门店编号
            ),
        );

        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['result_state']==1){

                if(sizeof($data)>1){

                    $result=  $data[1];
                }else{
                    $result['err_code'] = 50006;
                    $result['err_msg'] = '用户信息不存在';
                    return json_encode($result);
                }

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {

                switch ($data[0][0]['result_state']) {
                    case 0:
                        $result['err_code'] = 50003;
                        $result['err_msg'] = '用户不存在';
                        break;
                    case -1:
                        $result['err_code'] = 50004;
                        $result['err_msg'] = '服务器错误';
                        break;
                    default:
                        $result['err_code'] = 50003;
                        $result['err_msg'] = '用户不存在';   //0
                        break;
                }

                return json_encode($result);
            }
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }




    }


    //工单数目
    public  function  actionWorkordercount(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if( array_key_exists("store_id", $decode)
            && array_key_exists("manage_id", $decode)
            && array_key_exists("start_time", $decode)
            && array_key_exists("end_time", $decode)

        )
        {

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_WorkOrderCount',
            'Procedure_data_in'=>array(

                '_store_id'=>$decode['store_id'], //门店编号
                '_manage_id'=>$decode['manage_id'] , //管理员编号
                '_start_time'=>$decode['start_time'] , //管理员编号
                '_end_time'=>$decode['end_time']  //管理员编号

            ),

        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if(sizeof($data)>0){

                $result=$data[0][0];
                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {

                $result['err_code'] = 50009;
                $result['err_msg'] = '服务器错误';
                return json_encode($result);
            }
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }




    }


    //外勤工单  到店登记步骤
    public function actionStepstoregistration(){
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(    array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //步骤编号
            &&  array_key_exists("store_result", $decode)  //登记的结果

            &&  array_key_exists("remarks", $decode)  //备注
            &&  array_key_exists("manage_id", $decode)  //管理员编号
        )
        {

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_StepStoreGistration',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'] , //步骤编号
                '_storegistration_result'=>$decode['store_result'] , //登记的结果
                '_remarks'=>$decode['remarks'],  //备注
                '_manage_id'=>$decode['manage_id']  //管理员编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['result_state']='ok';
                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                    case -2:
                        $result['err_code'] = 50180;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    case -1:
                        $result['err_code'] = 50190;
                        $result['err_msg'] = '上一步骤未处理完';
                        break;
                    default:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }




    }

    //外勤工单  验车步骤  上传验车照片
    public function actionStepscheckcar(){
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //结果表主键

            &&  array_key_exists("carinfo_img", $decode)  //车况的照片
            &&  array_key_exists("carinfo_remark", $decode)  //车况的备注

            &&  array_key_exists("mileage_img", $decode)  //里程的照片
            &&  array_key_exists("fuel_meterimg", $decode)  //油表的照片
            &&  array_key_exists("mileage_data", $decode)  //里程的数据
            &&  array_key_exists("fuel_meter", $decode)  //油表的数据

            &&  array_key_exists("mileage_remark", $decode)  //里程油表的备注

            &&  array_key_exists("checkcar_pagimg", $decode)  //验车单的照片
            &&  array_key_exists("checkcar_pagremark", $decode)  //验车单的备注

            &&  array_key_exists("remarks", $decode)  //备注
            &&  array_key_exists("manage_id", $decode)  //管理员编号

            &&  array_key_exists("u_userid", $decode)  //用户编号

        ) {



        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = '参数不合法';
            return json_encode($result);
        };


        $rootPath = Yii::getAlias('@uploads').'/'.$decode['u_userid']; //上传根目录

        if( !file_exists($rootPath)){
            mkdir($rootPath,0777);
        }

        if( !is_dir($rootPath.'/workorder/')){
            mkdir ($rootPath.'/workorder/',0777);
        }


        try{

            $a = copy( Yii::getAlias('@tem_uploads').'/'.$decode['mileage_img'],  $rootPath.'/workorder/'.$decode['mileage_img']);  //里程的照片

            $b = copy( Yii::getAlias('@tem_uploads').'/'.$decode['fuel_meterimg'],  $rootPath.'/workorder/'.$decode['fuel_meterimg']);  //油表的照片


            if ($decode['checkcar_pagimg']=='' || $decode['checkcar_pagimg']==null){

                $decode['checkcar_pagimg']='no';
                $decode['checkcar_pagremark']='';
            }else{
                foreach(explode(',',$decode['checkcar_pagimg']) as $val){

                    $c = copy( Yii::getAlias('@tem_uploads').'/'.$val, $rootPath.'/workorder/'.$val); //验车单的照片
                };


            }


            foreach(explode(',',$decode['carinfo_img']) as $value){

                $d = copy( Yii::getAlias('@tem_uploads').'/'.$value, $rootPath.'/workorder/'.$value); //车况的照片
            }





        }catch (\Exception $ex) {
            $result['err_code'] = 40011;
            $result['err_msg'] =$ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_Stepscheckcar',
            'Procedure_data_in'=>array(
                '_u_userid'=>$decode['u_userid'],

                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //步骤结果ID
                '_carinfo_img'=>substr($decode['carinfo_img'],-1,1)==','?  $decode['carinfo_img']: $decode['carinfo_img'] .',', //车况的照片
                '_carinfo_remark'=>$decode['carinfo_remark'], //车况的备注
                '_mileage_img'=>$decode['mileage_img'], //里程的照片
                '_fuel_meterimg'=>$decode['fuel_meterimg'], //油表的照片
                '_mileage_data'=>$decode['mileage_data'], //里程的数据
                '_fuel_meter'=>$decode['fuel_meter'], //油表的数据
                '_mileage_remark'=>$decode['mileage_remark'], //里程油表的备注
                '_checkcar_pagimg'=> substr($decode['checkcar_pagimg'],-1,1)==','?  $decode['checkcar_pagimg']: $decode['checkcar_pagimg'] .',', //验车单的照片
                '_checkcar_pagremark'=>$decode['checkcar_pagremark'], //验车单的备注
                '_remarks'=>$decode['remarks'], //备注
                '_manage_id'=>$decode['manage_id'], //管理员编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result=$data[0][0];
                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {

                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                    case -2:
                        $result['err_code'] = 50180;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    case -1:
                        $result['err_code'] = 50190;
                        $result['err_msg'] = '上一步骤未处理完';
                        break;
                    default:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                }
            }
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }




    }

    //外勤工单  安装/拆除车载设备步骤
    public  function  actionStepsequipment(){
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(    array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //结果表主键


            &&  array_key_exists("type", $decode)  //类型
            &&  array_key_exists("equipment_num", $decode)  //车载设备编号
            &&  array_key_exists("equipment_phone", $decode)  //手机号
            &&  array_key_exists("netdevice_num", $decode)  //入网设备号

            &&  array_key_exists("remarks", $decode)  //备注
            &&  array_key_exists("manage_id", $decode)  //管理员编号
        )
        {

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_Stepsequipment',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //结果表主键
                '_type'=>$decode['type'], //类型
                '_equipment_num'=>$decode['equipment_num'] , //车载设备编号
                '_equipment_phone'=>$decode['equipment_phone'] , //手机号
                '_netdevice_num'=>$decode['netdevice_num'], //入网设备号
                '_remarks'=>$decode['remarks'],  //备注
                '_manage_id'=>$decode['manage_id']  //管理员编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['result_state']='ok';
                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                    case -2:
                        $result['err_code'] = 50180;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    case -1:
                        $result['err_code'] = 50190;
                        $result['err_msg'] = '上一步骤未处理完';
                        break;
                    default:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }


    }

    //外勤工单  车俩清洗步骤
    public  function  actionStepscarwashing(){
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(    array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //结果表主键

            &&  array_key_exists("plate_number", $decode)  //车牌编号
            &&  array_key_exists("carwashing_type", $decode)  // 1 现场清洗  2之前已清洗

            &&  array_key_exists("remarks", $decode)  //备注
            &&  array_key_exists("manage_id", $decode)  //管理员编号
        )
        {

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_StepsCarwashing',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //结果表主键

                '_plate_number'=>$decode['plate_number'], //车牌编号
                '_carwashing_type'=>$decode['carwashing_type'] , // 现场清洗  2之前已清洗

                '_remarks'=>$decode['remarks'],  //备注
                '_manage_id'=>$decode['manage_id']  //管理员编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['result_state']='ok';
                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                    case -2:
                        $result['err_code'] = 50180;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    case -1:
                        $result['err_code'] = 50190;
                        $result['err_msg'] = '上一步骤未处理完';
                        break;
                    default:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }


    }

    //外勤工单  车辆出场入场步骤
    public  function  actionStepsboundrecord(){
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(    array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //结果表主键

            &&  array_key_exists("bound_type", $decode)  //出入场类型
            &&  array_key_exists("plate_number", $decode)  //车牌编号
            &&  array_key_exists("bound_number", $decode)  // 车位编号

            &&  array_key_exists("remarks", $decode)  //备注
            &&  array_key_exists("manage_id", $decode)  //管理员编号
        )
        {

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_StepsBoundRecord',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //结果表主键

                '_bound_type'=>$decode['bound_type'],
                '_plate_number'=>$decode['plate_number'], //车牌编号
                '_bound_number'=>$decode['bound_number'] , // 车位编号

                '_remarks'=>$decode['remarks'],  //备注
                '_manage_id'=>$decode['manage_id']  //管理员编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['result_state']='ok';
                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                    case -2:
                        $result['err_code'] = 50180;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    case -1:
                        $result['err_code'] = 50190;
                        $result['err_msg'] = '上一步骤未处理完';
                        break;
                    default:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }


    }

    //外勤工单 随车证件与物品步骤
    public  function  actionStepsitems(){
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(    array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //结果表主键

//            &&  array_key_exists("three_risks", $decode)  //三标一险
//            &&  array_key_exists("driving_license", $decode)  //行驶证
//            &&  array_key_exists("car_keys", $decode)  // 车辆钥匙
            &&  array_key_exists("other_items", $decode)  // 其他物品
            &&  array_key_exists("attachment_info", $decode)  // 附件信息
            &&  array_key_exists("locker_num", $decode)  // 储物柜编号

            &&  array_key_exists("remarks", $decode)  //备注
            &&  array_key_exists("manage_id", $decode)  //管理员编号
        )
        {

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_StepsItems',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                'workstep_id'=>$decode['workstep_id'],  //结果表主键

                '_three_risks'=>1, //三标一险
                '_driving_license'=>1,//行驶证
                '_car_keys'=>1 , // 车辆钥匙
                '_other_items'=>$decode['other_items'], // 其他物品
                '_attachment_info'=>$decode['attachment_info'],  // 附件信息
                '_locker_num'=>$decode['locker_num'] , // 储物柜编号

                '_remarks'=>$decode['remarks'],  //备注
                '_manage_id'=>$decode['manage_id']  //管理员编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['result_state']='ok';
                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                    case -2:
                        $result['err_code'] = 50180;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    case -1:
                        $result['err_code'] = 50190;
                        $result['err_msg'] = '上一步骤未处理完';
                        break;
                    default:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }


    }

    //工单步骤结果完成确定
    public  function  actionStepscomplete(){
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(    array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //结果表主键
            &&  array_key_exists("manage_id", $decode)  //管理员编号
        )
        {

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_StepsComplete',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                'workstep_id'=>$decode['workstep_id'],  //结果表主键

                '_manage_id'=>$decode['manage_id']  //管理员编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['result_state']='ok';
                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                    case -2:
                        $result['err_code'] = 50180;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    case -1:
                        $result['err_code'] = 50190;
                        $result['err_msg'] = '上一步骤未处理完';
                        break;
                    default:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }


    }


    //查看验车步骤信息
    public  function  actionViewcheckcar(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //步骤编号
        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_ViewCheckCar',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //结果表主键
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)!=1 && sizeof($data)>0){

                $result=$data[1];


                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    default:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }








    }

    //查看车载设备步骤信息
    public  function  actionViewequipment(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //步骤编号
        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_ViewEquipment',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //结果表主键
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result=$data[1];


                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    default:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }








    }

    //查看车辆清洗步骤信息
    public  function  actionViewcarwashing(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //步骤编号
        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_ViewCarWashing',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //结果表主键
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result=$data[1];


                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    default:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }








    }

    //查看车辆出场入场步骤信息
    public  function  actionViewboundrecord(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //步骤编号
        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_ViewBoundRecord',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //结果表主键
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result=$data[1];


                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    default:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }








    }

    //查看 随车证件与物品步骤信息
    public  function  actionViewitems(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //步骤编号
        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_ViewItems',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //结果表主键
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result=$data[1];


                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    default:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }








    }

    //查询车主或租客的信息
    public  function  actionWorkorderuser(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("u_userid", $decode)  //工单编号

        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_WorkorderUser',
            'Procedure_data_in'=>array(
                '_u_userid'=>$decode['u_userid'], //用户编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result=$data[1];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '车主信息不存在';
                        break;
                    default:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '车主信息不存在';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }








    }

    //查看车时详细信息:todo
    public  function  actionWorkordercartimes(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("u_userid", $decode)  //工单编号
            &&  array_key_exists("u_userid", $decode)  //步骤编号
        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_WorkorderUser',
            'Procedure_data_in'=>array(
                '_u_userid'=>$decode['u_userid'], //用户编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result=$data[1];


                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    default:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }








    }

    //车损登记  车损列表 查看用户登记的车损
    public  function  actionChesunlist(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("cartime_id", $decode)  //车时编号
            &&  array_key_exists("order_id", $decode)  //订单编号
            &&  array_key_exists("workorder_type", $decode)  //工单类型

        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_CheSunList',
            'Procedure_data_in'=>array(
                '_cartime_id'=>$decode['cartime_id'], //用户编号
                '_order_id'=>$decode['order_id'], //用户编号
                '_workorder_type'=>$decode['workorder_type'], //用户编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                if( sizeof($data)>1){

                    $result=$data[1];
                }


                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                    default:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }

    }

    //车损登记  添加车损
    public  function  actionChesunadd(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("cartime_id", $decode)  //车时编号
            &&  array_key_exists("order_id", $decode)  //订单编号
            &&  array_key_exists("damage_option", $decode)  //车损部位
            &&  array_key_exists("damage_item", $decode)  //车损项目
            &&  array_key_exists("damage_status", $decode)  //车损状况
            //  &&  array_key_exists("damage_vehicle", $decode)  //车损类型 1、车主送车录入的车损    10、车主还车时补充录入的车损
            &&  array_key_exists("damage_cost", $decode)  //预估维修费
            //  &&  array_key_exists("damage_deal", $decode)  //处理意见
            &&  array_key_exists("workorder_type", $decode)  //工单类型
            &&  array_key_exists("manage_id", $decode)  //工单类型

        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        $decode['order_id']= $decode['order_id']==null || $decode['order_id']==''? 0:$decode['order_id'];
        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_CheSunAdd',
            'Procedure_data_in'=>array(
                '_cartime_id'=>$decode['cartime_id'], //用户编号
                '_order_id'=>$decode['order_id'], //用户编号
                '_damage_option'=>$decode['damage_option'], //
                '_damage_item'=>$decode['damage_item'], //
                '_damage_status'=>$decode['damage_status'], //
                //       '_damage_vehicle'=>$decode['damage_vehicle'], //
                '_damage_cost'=>$decode['damage_cost'], //
                //    '_damage_deal'=>$decode['damage_deal'], //
                '_workorder_type'=>$decode['workorder_type'], //
                '_manage_id'=>$decode['manage_id']
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );

        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['result_state']='ok';

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                    default:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }

    }

    //车损登记  修改车损
    public  function  actionChesunupdate(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(
            array_key_exists("damage_id", $decode)  //订单编号
            &&  array_key_exists("damage_option", $decode)  //车损部位
            &&  array_key_exists("damage_item", $decode)  //车损项目
            &&  array_key_exists("damage_status", $decode)  //车损状况
            //  &&  array_key_exists("damage_vehicle", $decode)  //车损类型 1、车主送车录入的车损    10、车主还车时补充录入的车损
            &&  array_key_exists("damage_cost", $decode)  //预估维修费
            //  &&  array_key_exists("damage_deal", $decode)  //处理意见
            &&  array_key_exists("manage_id", $decode)  //工单类型

        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_CheSunUpdate',
            'Procedure_data_in'=>array(
                '_damage_id'=>$decode['damage_id'], //用户编号
                '_damage_option'=>$decode['damage_option'], //
                '_damage_item'=>$decode['damage_item'], //
                '_damage_status'=>$decode['damage_status'], //
                //       '_damage_vehicle'=>$decode['damage_vehicle'], //
                '_damage_cost'=>$decode['damage_cost'], //
                //    '_damage_deal'=>$decode['damage_deal'], //
                //    '_workorder_type'=>$decode['workorder_type'], //
                '_manage_id'=>$decode['manage_id']
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );

        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['damage_id']=$decode['damage_id'];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                    default:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }

    }

    //额外费用记录
    public  function  actionAdditionalcost(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(array_key_exists("order_id", $decode)  //订单编号

        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_AdditionalCost',
            'Procedure_data_in'=>array(
                '_order_id'=>$decode['order_id'], //用户编号
            ),
//            'Procedure_data_out'=>array(
//                '_result_state'=>'_result_state'
//            )
        );

        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if( sizeof($data)>0){
                if($data[0][0]['result_state'] == 1){
                    $result['chesun']= $data[1];

                }else{
                    $result['chesun']= array();
                }

                //    if( sizeof($data)>2 ){
                foreach($data[$data[0][0]['result_state']+1] as $key=>$val ){
                    if($val['validate_type']==2){  //租客取车
                        $result['mileage']['mileage_get']=$val['mileage'];
                        $result['mileage']['mileage_get_time']=$val['validate_date'];

                        $result['oil']['oil_get']=$val['oil_mass'];
                        $result['oil']['oil_get_time']=$val['validate_date'];
                        $result['oil']['oil_cost']=$val['youfei_cost'];
                        $result['oil']['is_surecost']=$val['youfei_state'];
                        $result['service']['service_cost']=$val['fuwu_cost'];
                        $result['service']['is_surecost']=$val['fuwu_state'];
                    }else{   // 租客还车
                        $result['mileage']['mileage_return']=$val['mileage'];
                        $result['mileage']['mileage_return_time']=$val['validate_date'];
                        $result['mileage']['mileage_cost']=$val['gongli_cost'];
                        $result['mileage']['is_surecost']=$val['gongli_state'];

                        $result['oil']['oil_return']=$val['oil_mass'];
                        $result['oil']['oil_return_time']=$val['validate_date'];

                        $result['service']['service_cost']=$val['fuwu_cost'];
                        $result['service']['is_surecost']=$val['fuwu_state'];
                    }
                }
                //      }

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                    default:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }

    }

    //  添加和修改车损费用
    public  function  actionChesuncost(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(array_key_exists("damage_id", $decode)  //车损登记编号
            && array_key_exists("cost", $decode)  //车损费用
            && array_key_exists("manage_id", $decode)  //定损人编号
        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_CheSunCost',
            'Procedure_data_in'=>array(
                '_damage_id'=>$decode['damage_id'], //用户编号
                '_cost'=>$decode['cost'], //用户编号
                '_adminid'=>$decode['manage_id'], //用户编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if( $data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['result_state']= 'ok';

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }
                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                    default:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }

    }

    //添加和修改油费 公里废用额外项目表
    public  function  actionOilmileagecost(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(     array_key_exists("cartime_id", $decode)  //车时编号
            &&  array_key_exists("order_id", $decode)  //订单编号
            && array_key_exists("item_name", $decode)  //项目名
            && array_key_exists("item_cost", $decode)  //车损费用
            && array_key_exists("remark", $decode)  //备注
            && array_key_exists("item_types", $decode)  //额外项目类型
            && array_key_exists("manage_id", $decode)  //项目制造者编号

        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };


        $decode['order_id']= $decode['order_id']==null || $decode['order_id']==''? 0:$decode['order_id'];
        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_OilMileageCost',
            'Procedure_data_in'=>array(
                '_cartime_id'=>$decode['cartime_id'], //车时编号
                '_order_id'=>$decode['order_id'], //订单编号
                '_item_name'=>$decode['item_name'], //项目名
                '_item_cost'=>$decode['item_cost'], //车损费用
                '_remark'=>$decode['remark'], //备注
                '_item_types'=>$decode['item_types'], //额外项目类型
                '_manage_id'=>$decode['manage_id'], //项目制造者编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );
        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if( $data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['result_state']= 'ok';

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                    default:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }

    }

    //租客工单查出租期时间

    //查看车时详细信息:---lijia
    public  function  actionWorkordercartime(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("workorder_id", $decode)  //工单编号
        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_getcartimeinfo',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //用户编号
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){
            $result=$data[0];
            $AesManageForm=new AesManageForm($decode['key']);
            try{
                $result=$AesManageForm->encrypt(json_encode($result));

            }catch (\Exception $ex) {
                $result['err_code'] = 40007;
                $result['err_msg'] = $ex->getMessage(); //  加密失败

                return json_encode($result);
            }

            $result1['data']=$result;
            return json_encode($result1);
        }else {
            $result['err_code'] = 50280;
            $result['err_msg'] = '查询信息不存在';
            return json_encode($result);
        }
    }

    //查看订单详细信息:---lijia
    public  function  actionWorkorderrentalinfomation(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(  array_key_exists("workorder_id", $decode)  //工单编号
        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_getrentalorderinfo',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //用户编号
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){
            $result=$data[0];
            $AesManageForm=new AesManageForm($decode['key']);
            try{
                $result=$AesManageForm->encrypt(json_encode($result));

            }catch (\Exception $ex) {
                $result['err_code'] = 40007;
                $result['err_msg'] = $ex->getMessage(); //  加密失败

                return json_encode($result);
            }

            $result1['data']=$result;
            return json_encode($result1);
        }else {
            $result['err_code'] = 50280;
            $result['err_msg'] = '查询信息不存在';
            return json_encode($result);
        }
    }

    //待付项目结算查询
    public  function  actionViewaitpayclose(){
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(

            array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //结果表主键

        )
        {

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_ViewaitpayClose',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                '_workstep_id'=>$decode['workstep_id'],  //结果表主键
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){
                $result['waitfp_total']=0;
                $result['item_total']=0;
                $result['sure_state']=1;
                if($data[1][0]['waitfp_count']==1){
                    $result['waitfp_count']=1;
                    $result['waitfp']=$data[2];
                    foreach($data[2] as $key=>$val){
                        $result['waitfp_total']+=$val['waitfp_cost'];
                        if($val['waitfp_status']==0){
                            $result['sure_state']=0;
                        }
                    }

                    if(array_key_exists(3, $data) ){
                        $result['sure_state']=0;
                        $result['item_count']=1;
                        foreach($data[3] as $key=>$val){
                            $result['item_total']+=$val['cost'];
                        }

                        $result['item']=$data[3];
                    }else{
                        $result['item_count']=0;
                        $result['item']=array();
                    }

                }else{
                    $result['waitfp_count']=0;
                    if(array_key_exists(2, $data) ){
                        $result['sure_state']=0;
                        $result['item_count']=1;
                        $result['item']=$data[2];

                        foreach($data[2] as $key=>$val){
                            $result['item_total']+=$val['cost'];
                        }
                    }else{
                        $result['item_count']=0;
                        $result['item']=array();
                    }

                }

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    default:
                        $result['err_code'] = 50280;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }


    }

    //立即纳入结算
    public  function actionCloseaccountnow(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(     array_key_exists("order_id", $decode)  //订单编号
            &&  array_key_exists("manage_id", $decode)  //用户编号

        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //  in _order_id int,in _waitfp_type int,in _action_type int,in _action_num int
        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'oeder_addtowaitforpaylist',
            'Procedure_data_in'=>array(
                '_order_id'=>$decode['order_id'], //车时编号
                '_waitfp_type'=>3, //订单编号
                '_action_type'=>1, //订单编号
                '_action_num'=>$decode['manage_id'], //订单编号
            ),
        );
        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if( $data[0][0]['result'] == 1 && sizeof($data)>0){

                $result['order_id']= $decode['order_id'];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                    default:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }


    }


    //待付项目结算 步骤完成
    public  function  actionStepswaitpayclose(){
        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(    array_key_exists("workorder_id", $decode)  //工单编号
            &&  array_key_exists("workstep_id", $decode)  //结果表主键
            &&  array_key_exists("manage_id", $decode)  //管理员编号
        )
        {

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_StepsWaitPayClose',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //工单编号
                'workstep_id'=>$decode['workstep_id'],  //结果表主键

                '_manage_id'=>$decode['manage_id']  //管理员编号
            ),
            'Procedure_data_out'=>array(
                '_result_state'=>'_result_state'
            )
        );


        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }



        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if($data[0][0]['_result_state'] == 1 && sizeof($data)>0){

                $result['workorder_id']=$decode['workorder_id'];
                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                    case -2:
                        $result['err_code'] = 50180;
                        $result['err_msg'] = '工单步骤不存在';
                        break;
                    case -1:
                        $result['err_code'] = 50190;
                        $result['err_msg'] = '上一步骤未处理完';
                        break;
                    case -3:
                        $result['err_code'] = 50160;
                        $result['err_msg'] = '用户存在未支付的项目';
                        break;
                    default:
                        $result['err_code'] = 50170;
                        $result['err_msg'] = '当前步骤已经记录结果';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }



    }


    //todo: 身份认证
    //后勤提交和修改用户的身份认证照片
    public function actionUseridentityimg(){

        $result=array();
        $this->layout = false;

        //判断种子  解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数
        if (array_key_exists("u_userid", $decode)

            && array_key_exists("idc_first_img", $decode)  //身份证正面
            && array_key_exists("idc_secend_img", $decode)  //身份证反面
            && array_key_exists("lic_first_img", $decode)  //驾驶证正本
            && array_key_exists("lic_secend_img", $decode)  //驾驶证副本

            && array_key_exists("manage_id", $decode)  //管理员编号
        ) {


        } else {
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };
        $rootPath = Yii::getAlias('@uploads').'/'.$decode['u_userid']; //上传根目录

        if( !file_exists($rootPath)){
            mkdir ($rootPath,0777);
        }

        if( !is_dir($rootPath.'/idcardlicense/')){
            mkdir ($rootPath.'/idcardlicense/',0777);
        }

        try{

            $a = copy( Yii::getAlias('@tem_uploads').'/'.$decode['idc_first_img'],  $rootPath.'/idcardlicense/'.$decode['idc_first_img']);

            $b = copy( Yii::getAlias('@tem_uploads').'/'.$decode['idc_secend_img'],  $rootPath.'/idcardlicense/'.$decode['idc_secend_img']);

            $c = copy( Yii::getAlias('@tem_uploads').'/'.$decode['lic_first_img'], $rootPath.'/idcardlicense/'.$decode['lic_first_img']);

            $d = copy( Yii::getAlias('@tem_uploads').'/'.$decode['lic_secend_img'], $rootPath.'/idcardlicense/'.$decode['lic_secend_img']);


        }catch (\Exception $ex) {
            $result['err_code'] = 40011;
            $result['err_msg'] =$ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        $ProcedureData = array(
            'Procedure_name' => 'F_Api_UserIdentity',
            'Procedure_data_in' => array(
                'u_userid' =>$decode['u_userid'],

                'idcard_firstimg' =>$decode['u_userid'].'/idcardlicense/'.$decode['idc_first_img'],
                'idcard_secendimg' =>$decode['u_userid'].'/idcardlicense/'.$decode['idc_secend_img'],

                'license_firstimg' =>$decode['u_userid'].'/idcardlicense/'.$decode['lic_first_img'],
                'license_secendimg' =>$decode['u_userid'].'/idcardlicense/'.$decode['lic_secend_img'],
                '_manage_id'=>$decode['manage_id']
            ),
            'Procedure_data_out' => array(
                '_result_state' => '_result_state'
            )
        );



        $UserManage = new FieldworkEnpty();

        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);


        } catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        if (is_array($data) && !array_key_exists('result', $data) && !array_key_exists('value', $data)) {

            if ($data[0][0]['_result_state'] == 1) {
                $result['user_id']=$decode['u_userid'];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败
                    return json_encode($result);
                }
                $result1['data']=$result;

                return json_encode($result1);
            } else {
                switch ($data[0][0]['_result_state']) {
                    case 1:
                        $result['err_code'] = 50050;
                        $result['err_msg'] = '该用户身份认证已成功,不需要重复认证';
                        break;
                    case 0:
                        $result['err_code'] = 50051;
                        $result['err_msg'] = '该用户身份认证正在审核中';
                        break;
                    default:  //3
                        $result['err_code'] = 50051;
                        $result['err_msg'] = '该用户身份认证正在审核中';
                        break;

                }
            }
            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] = $data['value'];//Procedure数据返回错误
            return json_encode($result);
        }


    }


    //后勤查询用户身份认证信息
    public function actionUseridentitygetinfo(){
        $result=array();
        $this->layout = false;

        //判断种子  解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数
        if (array_key_exists("u_userid", $decode)   )
        {


        } else {
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        $ProcedureData = array(
            'Procedure_name' => 'F_api_Useridentity_Getinfo',
            'Procedure_data_in' => array(
                '_u_userid' =>$decode['u_userid'],

            ),
        );

        $UserManage = new FieldworkEnpty();

        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);


        } catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        if (is_array($data) && !array_key_exists('result', $data) && !array_key_exists('value', $data)) {

            if ($data[0][0]['_result'] == 1) {

                $result = $data[1][0];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败
                    return json_encode($result);
                }
                $result1['data']=$result;

                return json_encode($result1);
            } else {
                switch ($data[0][0]['_result']) {
                    case -1:
                        $result['err_code'] = 51001;
                        $result['err_msg'] = '用户不存在';
                        break;
                    default:  //3
                        $result['err_code'] = 51001;
                        $result['err_msg'] = '用户不存在';
                        break;

                }
            }
            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] = $data['value'];//Procedure数据返回错误
            return json_encode($result);
        }


    }

    //外勤补填身份认证信息
    public function actionAdduseridentityinfo(){
        $result=array();
        $this->layout = false;

        //判断种子  解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数
        if (array_key_exists("user_id", $decode)
            && array_key_exists("driverlicense", $decode)
            && array_key_exists("driverrecordcode", $decode)
            && array_key_exists("startdate", $decode)
            && array_key_exists("expiration_date", $decode)
            && array_key_exists("result_state", $decode)
            && array_key_exists("quasi_drivingtype", $decode)
            && array_key_exists("useful_time", $decode)
            && array_key_exists("license_nationality", $decode)
            && array_key_exists("userfullname", $decode)
            && array_key_exists("useridnumber", $decode)
            && array_key_exists("idcard_expiratime", $decode)
            && array_key_exists("user_sex", $decode)
            && array_key_exists("user_birthday", $decode)
            && array_key_exists("idcard_startime", $decode)
            && array_key_exists("sign_organiza", $decode)
            && array_key_exists("manage_id", $decode)
        )
        {


        } else {
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        $ProcedureData = array(
            'Procedure_name' => 'F_api_Useridentity_updateinfo',
            'Procedure_data_in' => array(
                '_user_id' =>$decode['user_id'],
                '_driverlicense' =>$decode['driverlicense'],
                '_driverrecordcode' =>$decode['driverrecordcode'],
                '_startdate' =>$decode['startdate'],
                '_expiration_date' =>$decode['expiration_date'],
                '_result_state' =>$decode['result_state'],
                '_quasi_drivingtype' =>$decode['quasi_drivingtype'],
                '_useful_time' =>$decode['useful_time'],
                '_license_nationality' =>$decode['license_nationality'],
                '_userfullname' =>$decode['userfullname'],
                '_useridnumber' =>$decode['useridnumber'],
                '_idcard_expiratime' =>$decode['idcard_expiratime'],
                '_user_sex' =>$decode['user_sex'],
                '_user_birthday' =>$decode['user_birthday'],
                '_idcard_startime' =>$decode['idcard_startime'],
                '_sign_organiza' =>$decode['sign_organiza'],
                '_manage_id' =>$decode['manage_id'],

            ),
        );


        $UserManage = new FieldworkEnpty();

        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);


        } catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        if (is_array($data) && !array_key_exists('result', $data) && !array_key_exists('value', $data)) {

            if ($data[0][0]['_result'] == 1) {

                $result['user_id']=$decode['user_id'];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败
                    return json_encode($result);
                }
                $result1['data']=$result;

                return json_encode($result1);
            } else {
                $result['err_code'] = 50290;
                $result['err_msg'] = '服务器错误';
            }
            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] = $data['value'];//Procedure数据返回错误
            return json_encode($result);
        }

    }


    //todo: 车辆认证
    //后勤提交和修改车辆的认证信息
    public function actionCaridentityimg(){


        //判断种子  解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数
        if (array_key_exists("u_userid", $decode)
            && array_key_exists("usercar_id", $decode) // 车辆编号  更新泽为0  修改则传正确的车辆编号
            && array_key_exists("veh_first_img", $decode)  //行驶证正本照片
            && array_key_exists("veh_second_img", $decode)  //行驶证副本照片
            && array_key_exists("insurance_img", $decode)  //交强险保单照片
            && array_key_exists("busin_img", $decode)  //商业险保单照片

            && array_key_exists("cars_img", $decode)  //车辆照片  多张 逗号分割

            && array_key_exists("manage_id", $decode)  //管理员编号
        ) {


        } else {
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        $rootPath = Yii::getAlias('@uploads').'/'.$decode['u_userid']; //上传根目录

        if( !file_exists($rootPath)){
            mkdir ($rootPath,0777);
        }

        if( !is_dir($rootPath.'/insurance/')){
            mkdir ($rootPath.'/insurance/',0777);
        }

        if( !is_dir($rootPath.'/carimg/')){
            mkdir ($rootPath.'/carimg/',0777);
        }

        try{

            $a = copy( Yii::getAlias('@tem_uploads').'/'.$decode['veh_first_img'],  $rootPath.'/insurance/'.$decode['veh_first_img']);

            $b = copy( Yii::getAlias('@tem_uploads').'/'.$decode['veh_second_img'],  $rootPath.'/insurance/'.$decode['veh_second_img']);

            $c = copy( Yii::getAlias('@tem_uploads').'/'.$decode['insurance_img'], $rootPath.'/insurance/'.$decode['insurance_img']);

            $d = copy( Yii::getAlias('@tem_uploads').'/'.$decode['busin_img'], $rootPath.'/insurance/'.$decode['busin_img']);

            foreach(explode(',',$decode['cars_img']) as $value){

                $e = copy( Yii::getAlias('@tem_uploads').'/'.$value, $rootPath.'/carimg/'.$value); //车辆的照片
            }


        }catch (\Exception $ex) {
            $result['err_code'] = 40011;
            $result['err_msg'] =$ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        $ProcedureData = array(
            'Procedure_name' => 'F_Api_UserCarsManage',
            'Procedure_data_in' => array(
                'car_carid'=>$decode['usercar_id'],
                'u_userid' =>$decode['u_userid'],
                'vehicle_first_img' => $decode['u_userid'].'/insurance/'.$decode['veh_first_img'],  //行驶证正本照片
                'vehicle_second_img'=>$decode['u_userid'].'/insurance/'.$decode['veh_second_img'], //行驶证副本照片
                'insurance_img' =>$decode['u_userid'].'/insurance/'.$decode['insurance_img'],  //交强险保单照片
                'business_img' =>$decode['u_userid'].'/insurance/'.$decode['busin_img'],  //商业险保单照片

                'cars_img' => substr($decode['cars_img'],-1,1)==','?  $decode['cars_img']: $decode['cars_img'] .',',  //车辆照片  多张 逗号分割

                'manage_id' =>$decode['manage_id'],

            ),
            'Procedure_data_out' => array(
                'result_state' => 'result_state'
            )
        );



        $UserManage = new FieldworkEnpty();

        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);


        } catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        if (is_array($data) && !array_key_exists('result', $data) && !array_key_exists('value', $data)) {

            if ($data[0][0]['result_state'] == 1) {
                $result['user_id']=$decode['u_userid'];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败
                    return json_encode($result);
                }
                $result1['data']=$result;

                return json_encode($result1);
            } else {
                switch ($data[0][0]['_result_state']) {
                    case 0:
                        $result['err_code'] = 51011;
                        $result['err_msg'] = '车辆不存在';
                        break;
                    default:  //3
                        $result['err_code'] = 50051;
                        $result['err_msg'] = '服务器错误';
                        break;

                }
            }
            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] = $data['value'];//Procedure数据返回错误
            return json_encode($result);
        }



    }
    //后勤查询用户车辆认证信息
    public function actionCargetinfo(){

        $result=array();
        $this->layout = false;

        //判断种子  解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数
        if (array_key_exists("car_carid", $decode)   )
        {

        } else {
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        $ProcedureData = array(
            'Procedure_name' => 'F_api_Caridentity_Getinfo',
            'Procedure_data_in' => array(
                '_car_carid' =>$decode['car_carid'],
            ),
        );

        $UserManage = new FieldworkEnpty();

        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);


        } catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        if (is_array($data) && !array_key_exists('result', $data) && !array_key_exists('value', $data)) {

            if ($data[0][0]['_result'] == 1) {

                $result = $data[1][0];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败
                    return json_encode($result);
                }
                $result1['data']=$result;

                return json_encode($result1);
            } else {
                switch ($data[0][0]['_result']) {
                    case -1:
                        $result['err_code'] = 51003;
                        $result['err_msg'] = '车辆不存在';
                        break;
                    default:  //3
                        $result['err_code'] = 51003;
                        $result['err_msg'] = '车辆不存在';
                        break;

                }
            }
            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] = $data['value'];//Procedure数据返回错误
            return json_encode($result);
        }




    }
    //后勤补填用户车辆认证信息
    public function actionAddcarinfo(){
        $result=array();
        $this->layout = false;

        //判断种子  解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数
        if (array_key_exists("usercar_id", $decode)
            && array_key_exists("buying_time", $decode)
            && array_key_exists("buying_address", $decode)
            && array_key_exists("buying_price", $decode)
            && array_key_exists("usercar_color", $decode)
            && array_key_exists("usercar_image", $decode)
            && array_key_exists("isuserd", $decode)
            && array_key_exists("result_state", $decode)  // 审核状态

            && array_key_exists("vehicle_code", $decode)
            && array_key_exists("car_plate", $decode)
            && array_key_exists("vehicle_name", $decode)
            && array_key_exists("identification", $decode)
            && array_key_exists("engine_code", $decode)
            && array_key_exists("insurance_no", $decode)
            && array_key_exists("insurance_date", $decode)
            && array_key_exists("vehicle_registetime", $decode)
            && array_key_exists("vehicle_endtime", $decode)
            && array_key_exists("vehicle_number", $decode)
            && array_key_exists("business_innum", $decode)
            && array_key_exists("vehicle_area", $decode)
            && array_key_exists("is_limitedcity", $decode)

            && array_key_exists("manage_id", $decode)

        )
        {


        } else {
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        $ProcedureData = array(
            'Procedure_name' => 'F_api_Caridentity_updateinfo',
            'Procedure_data_in' => array(
                '_usercar_id' =>$decode['usercar_id'],
                '_buying_time' =>$decode['buying_time'],
                '_buying_address' =>$decode['buying_address'],
                '_buying_price' =>$decode['buying_price'],
                '_usercar_color' =>$decode['usercar_color'],
                '_usercar_image' =>$decode['usercar_image'],
                '_isuserd' =>$decode['isuserd'],
                '_result_state' =>$decode['result_state'],

                '_vehicle_code' =>$decode['vehicle_code'],
                '_car_plate' =>$decode['car_plate'],
                '_vehicle_name' =>$decode['vehicle_name'],
                '_identification' =>$decode['identification'],
                '_engine_code' =>$decode['engine_code'],
                '_insurance_no' =>$decode['insurance_no'],
                '_insurance_date' =>$decode['insurance_date'],
                '_vehicle_registetime' =>$decode['vehicle_registetime'],
                '_vehicle_endtime' =>$decode['vehicle_endtime'],
                '_vehicle_number' =>$decode['vehicle_number'],
                '_business_innum' =>$decode['business_innum'],
                '_vehicle_area' =>$decode['vehicle_area'],
                '_is_limitedcity' =>$decode['is_limitedcity'],

                '_manage_id' =>$decode['manage_id'],
            ),
        );


        $UserManage = new FieldworkEnpty();

        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);


        } catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }


        if (is_array($data) && !array_key_exists('result', $data) && !array_key_exists('value', $data)) {

            if ($data[0][0]['_result'] == 1) {

                $result['usercar_id']=$decode['usercar_id'];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败
                    return json_encode($result);
                }
                $result1['data']=$result;

                return json_encode($result1);
            } else {
                $result['err_code'] = 50290;
                $result['err_msg'] = '服务器错误';
            }
            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] = $data['value'];//Procedure数据返回错误
            return json_encode($result);
        }
    }


    //费用确认  步骤
    public function actionSurecost(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(     array_key_exists("order_id", $decode)  //订单编号  泊车订单费用  租车订单费用
            &&  array_key_exists("type", $decode)  // 1 是租车订单  2 是泊车订单
            &&  array_key_exists("manage_id", $decode)  //用户编号

        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //  in _order_id int,in _waitfp_type int,in _action_type int,in _action_num int
        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'oeder_addtowaitforpaylist',
            'Procedure_data_in'=>array(
                '_order_id'=>$decode['order_id'], //车时编号
                '_waitfp_type'=>3, //订单编号
                '_action_type'=>1, //订单编号
                '_action_num'=>$decode['manage_id'], //订单编号
            ),
        );
        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if( $data[0][0]['result'] == 1 && sizeof($data)>0){

                $result['order_id']= $decode['order_id'];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);
            }else {
                switch ($data[0][0]['_result_state']) {

                    case 0:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                    default:
                        $result['err_code'] = 50290;
                        $result['err_msg'] = '服务器错误';
                        break;
                }
            }

            return json_encode($result);
        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }

    }



    //工单完成check
    public function actionCompleteworkcheck(){

        $result=array();
        $this->layout = false;

        //判断种子和解密数据
        $PublicMethod=new PublicMethod();
        $decode=$PublicMethod->parameters_check();
        if(array_key_exists("err_code", $decode)){
            return json_encode($decode);
        }

        //判断参数是否合法
        if(     array_key_exists("workorder_id", $decode)  //工单编号

        ){

        }else{
            $result['err_code'] = 40000;
            $result['err_msg'] = "参数不合法";
            return json_encode($result);
        };

        //  in _order_id int,in _waitfp_type int,in _action_type int,in _action_num int
        //调用存储过程
        $ProcedureData=array(
            'Procedure_name'=>'F_api_CheckUserCarInfo',
            'Procedure_data_in'=>array(
                '_workorder_id'=>$decode['workorder_id'], //车时编号
            ),
        );
        $UserManage = new FieldworkEnpty();
        try {

            $data = $UserManage->Usermaininfo_query($ProcedureData);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40001;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return json_encode($result);
        }

        //判断调用的存储过程
        if (is_array($data) && !array_key_exists('result',$data ) && !array_key_exists('value',$data) ){

            if( $data[0][0]['@result1']=1 && $data[0][0]['@result2']=1 ){

                $result['workorder_id']= $decode['workorder_id'];

                $AesManageForm=new AesManageForm($decode['key']);
                try{
                    $result=$AesManageForm->encrypt(json_encode($result));

                }catch (\Exception $ex) {
                    $result['err_code'] = 40007;
                    $result['err_msg'] = $ex->getMessage(); //  加密失败

                    return json_encode($result);
                }

                $result1['data']=$result;
                return json_encode($result1);


            }elseif($data[0][0]['@result1']=0 && $data[0][0]['@result2']=0 ){

                $result['err_code'] = 58080;
                $result['err_msg'] ='请补全客户的个人信息和车辆信息'; //  服务器错误
            }else{
                if($data[0][0]['@result1']=1){  //车辆车辆信息补全

                    $result['err_code'] = 58081;
                    $result['err_msg'] ='请补全客户的个人信息'; //  服务器错误
                }else{
                    $result['err_code'] = 58082;
                    $result['err_msg'] ='请补全客户的车辆信息'; //  服务器错误
                }

            }

            return json_encode($result);

        } else {
            $result['err_code'] = 40002;
            $result['err_msg'] =$data['value']; //底层数据报错
            return json_encode($result);
        }

    }













    //todo: 客户车时查询


    //todo: 客户订单查询


    //todo: 客户相关工单查询



}